package com.joven.shelltest.config;

import org.apache.catalina.connector.Connector;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author wzj
 * @since 2024/10/8 10:02
 */

@Configuration
public class MultiPortConfig {
    @Bean
    public ServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();

        // 配置主端口8080
//        factory.setPort(8080);

        // 添加额外的Connector监听8081端口
        Connector additionalConnector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        additionalConnector.setPort(8081);
        factory.addAdditionalTomcatConnectors(additionalConnector);

        // 可添加更多Connector监听不同端口

        return factory;
    }
}
